package com.xinhuajs.articlemg.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.xinhuajs.articlemg.pojo.Article;
import com.xinhuajs.articlemg.pojo.User;
import com.xinhuajs.articlemg.service.IRecordService;
import com.xinhuajs.articlemg.utils.Page_User;

@Controller
@RequestMapping("/record")
public class RecordController {
	@Autowired
	private IRecordService recordService;

	@RequestMapping("/recordList")
	public String recordList(Model model, HttpServletRequest request) {

		/**
		 * 鑾峰彇椤甸潰鍙傛暟
		 */
		String page = request.getParameter("page");
		String selectRole = request.getParameter("selectRole");
		/**
		 * 鎬昏褰曟暟
		 */
		int count = 0;
		int currentPage = 0;
		Page_User pages = null;
		List<Article> article = null;

		/**
		 * 鍒ゆ柇褰撳墠椤�
		 */
		if (page == null || page.equals("")) {
			currentPage = 1;
		} else {
			currentPage = Integer.parseInt(page);
		}

		/* 鑾峰彇鏌ヨ鎬昏褰曟暟 */
		count = recordService.selectCount();

		/* 閫氳繃Page杩欎釜绫诲彲浠ヨ幏鍙栧垎椤电殑璧峰涓嬫爣鍜屾潯鏁� */
		pages = new Page_User(count, currentPage);

		/* 鎷兼帴鍒嗛〉璇彞 */
		article = recordService.limit(pages.getStartIndex(), pages.getPagesize());

		model.addAttribute("pages", pages);
		model.addAttribute("articlelist", article);

		return "forward:/WEB-INF/views/inuser/recordList.jsp";
	}

}
